Skip to content

Move Zcash Sapling and transparent funds to Ironwood - #1568

Draft
sneurlax wants to merge 2 commits into
feat/zcash-paramsfrom
feat/zcash-pools
Draft

sneurlax wants to merge 2 commits into
feat/zcash-paramsfrom
feat/zcash-pools

Conversation

@sneurlax

@sneurlax sneurlax commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add ZcashWallet.prepareMoveToIronwood(pool): a transaction that moves what the wallet holds in the Sapling pool, or its transparent coins, to its own Ironwood receiver. A send spends Ironwood funds only, so this is how funds received on the Sapling or transparent receiver of the wallet's address become spendable.
  • Add ZcashWallet.movableFunds(): what each of the two pools holds that such a move can take.
  • A prepared move is confirmed with confirmSend and dropped with cancelSend, as a send is.
  • List a send that pays only the wallet's own address, which a move is, as a transfer to self.

This PR has no view. The view that offers the moves is #1569. The moves are covered here by unit tests and by two legs of the regtest end-to-end test.

Stacked on #1566.

Commits

  1. feat: move Zcash Sapling and transparent funds to Ironwood.

Size

10 files, +2108/-83. About 1070 lines are code: the send service (+655: the two prepared transactions, the Sapling witness scan, the two preparations, the selection and fee arithmetic, and the call of the native transparent builder), the wallet (about 285 changed lines, of which about 60 move the body of prepareSend into a method the move shares), the pending-send store (+120 for the move records) and the history mapper (about 50). About 990 lines are unit tests and 80 are the end-to-end legs.

How it works

  • The backend builds two transactions for this: Sapling notes to an Ironwood output with Sapling change (prepareNativeSaplingPayment), and transparent coins to an Ironwood output (prepareNativeShieldingSend). Neither can pay another pool, which is why this is a move to the wallet's own address and not a choice of source in the send form.
  • One move takes at most the 50 largest notes or coins. What is left takes another move. A note or coin of 5000 zatoshis or less is left out: ZIP 317 charges 5000 for each input, so it would cost what it holds, and enough of them would make the whole move unaffordable.
  • movableFunds() reports a pool as empty when its first move could not pay its fee, by ZIP 317's arithmetic (15000 for one transparent coin, 20000 for up to two Sapling notes). The fee of a prepared move is still the backend's quote.
  • Sapling: the sync keeps no witnesses, so the move scans the blocks from its oldest note to the tip again, with witnesses. It uses a note only if the scan returns the same note, unspent, with its witness. The roots the scan ends on have to be the roots of the node's trees at the tip (derived from the node's tree state with a scan of no blocks, as the backend does for Ironwood spends), and the tip block and its trees have to be unchanged when fetched again. The notes are reserved in the pending-send state like those of a send, so the move is listed while it is not mined.
  • Transparent: the coins are signed with the keys of the receivers they were found on. A transparent move has no entry in the pending-send state, which holds shielded notes. The wallet records it (txid, fee, expiry height, coins) in the same encrypted file as the pending sends, in a new optional field, before the transaction is submitted. The record keeps the coins out of the next move until the transaction is mined or expires, and it carries the fee, which the node does not report for the mined transaction. The record is removed only when the node refuses the transaction's first submission.
  • The record is in that file, and not in WalletInfo.otherData, because WalletInfo's update methods read the row and write it back in a later step, so a refresh that updates the chain height at the same time could write the record away. The file is read and written under its lock.
  • The Sapling parameters, which a move from Sapling is proven with, are fetched before the send lock is taken, as for a send.

Known limits

  • A move from Sapling leaves one zatoshi of Sapling change. The backend's check of a built Sapling-funded transaction expects no Sapling outputs when there is no change, and the builder always pads them to two, so a transaction without change is refused. The fix belongs in zcash_flutter.
  • Notes and coins of 5000 zatoshis or less, and the zatoshi above, stay in their pool.
  • A move from Sapling is refused when its oldest note is 20000 or more blocks old. The witness scan downloads every block since that note in one request and holds them in memory. Sapling funds from before that, which is most of what a restored wallet would hold, stay unspendable until zcash_flutter keeps witnesses current during sync. As for a send, the server learns the height of the oldest note.
  • Orchard funds from before the Ironwood upgrade cannot be moved. Their migration (ZIP 318) is a scheduled process and is not part of this PR.
  • A move of transparent coins is not listed while it is not mined. Its coins are held back meanwhile, and the transparent balance still counts them until a block holds the transaction.
  • While a move from Sapling is not mined, the total balance does not yet show its fee as spent.
  • The expiry height recorded for a move of transparent coins is the target height plus 40, the builder's default: the backend does not report the one it set.
  • A move of transparent coins whose submission fails without an answer from the node holds its coins until that expiry, about 40 blocks, because the node may have it.
  • The records of transparent moves are not part of a Stack Backup and are not rebuilt by a restore from the recovery phrase. A wallet without the record lists a mined move as a send of its fee, as it lists every send it has no record of. The records are small and are kept: only their list of coins is dropped once they expire.
  • Proving a move runs on the UI isolate, as for a send.

Not changed here

  • A send from Ironwood to the wallet's own Unified Address was listed as a send. With this PR it is listed as a transfer to self, like a move. Its balance handling while it is not mined is unchanged.
  • WalletInfo's update methods can lose an update to one another, for every coin. This PR avoids them for its record and leaves them as they are.

Verification

At this PR's head (140c9ea14):

  • The Zcash tests: 150 pass. New: a move from Sapling with a faked chain, scan and builder (the scan range, the notes spent, the dust note left out, the change zatoshi, the reservation), the witness scan's refusals, each by its message (a note without its witness, a missing note, a note of another value, a spent note, a changed tip block, changed trees, roots that are not the node's, a missing Ironwood root), the empty Ironwood tree, the block limit, a move of transparent coins (immature, held and dust coins left out, nothing built when nothing is free), the amounts offered at the fee boundaries, the wallet's hold on the coins of a transparent move (not held when the node refuses the first submission, held when the submission has no answer, still held when a resubmission is refused, held when the node takes it), the store keeping the moves across a save of the pending sends and across concurrent updates, the Sapling parameters fetched outside the send lock, and the transfer-to-self rows.
  • The end-to-end suite against zebrad 7.0.0 and lightwalletd 0.6.1: 1/1, run at the top of the stack (Add a Zcash migration view to the More menu #1569, whose commit adds no wallet code). It moves Sapling funds and transparent funds to Ironwood with the real scan and builder, mines both, and checks the balances, the held funds and the history rows.
  • flutter analyze on the changed Dart files: no issues. CI's format check on them: clean.
  • The full flutter test suite: 1587 passed, 8 skipped, run at the top of the stack (Add a Zcash migration view to the More menu #1569).

Not covered by a test: the release of a transparent move's coins at its expiry height, and the native transparent builder with an empty Ironwood tree.

Brings in the anchor depth, the settling of failed and stale sends, and
the balance of a send to the wallet's own address. Adapted for the moves:

- A move from Sapling anchors as deep as a send and leaves younger notes
  out. A move of transparent coins names the Ironwood root at that depth.
- A transparent move the node refuses, or that expired, is no longer the
  prepared transaction.
- An unmined move from Sapling costs its fee in the balance, and what it
  moves is pending.
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.26078% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.36%. Comparing base (dd0f567) to head (1bfcf03).

Files with missing lines Patch % Lines
lib/wallets/wallet/intermediate/zcash_send.dart 77.10% 68 Missing ⚠️
lib/wallets/wallet/impl/zcash_wallet.dart 72.88% 32 Missing ⚠️
.../wallet/intermediate/zcash_pending_send_store.dart 97.61% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           feat/zcash-params    #1568      +/-   ##
=====================================================
+ Coverage              22.13%   22.36%   +0.22%     
=====================================================
  Files                   1158     1158              
  Lines                 116530   116961     +431     
=====================================================
+ Hits                   25797    26157     +360     
- Misses                 90733    90804      +71     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant